package com.beaut.project.control;


import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.beaut.project.service.GroupService;



/**
 * 负责系统管理
 * @author jzk
 *
 */
@Controller
@RequestMapping("/group")
public class GroupController extends BaseControl{
	@Autowired 
	private GroupService groupService; 
	
    
    @RequestMapping(value = "/listDepartment", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String listDepartment(HttpServletRequest request) {
    	return groupService.listDepartment();
    }

    @RequestMapping(value = "/addDepartNode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String addDepartNode(HttpServletRequest request) {
    	String id=UUID.randomUUID().toString();//区域id
    	String name = request.getParameter("name");
    	String sort = request.getParameter("sort");
    	String parent_id = request.getParameter("parent_id");
    	String parent_name = request.getParameter("parent_name");
    	Map<String,String> childNodeMap = new HashMap<String,String>();
    	
    	childNodeMap.put("id", id); 
    	childNodeMap.put("name", name); 
    	childNodeMap.put("sort", sort); 
    	childNodeMap.put("parent_id", parent_id);
    	childNodeMap.put("parent_name",parent_name);
    	return groupService.addDepartNode(childNodeMap);
    }
    
    @RequestMapping(value = "/updateDepartNode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateDepartNode(HttpServletRequest request) {
    	
    	String id = request.getParameter("id");
    	String name = request.getParameter("name");
    	String sort = request.getParameter("sort");
    	String parent_id = request.getParameter("parent_id");
    	String parent_name = request.getParameter("parent_name");
    	Map<String,String> childNodeMap = new HashMap<String,String>();
    	
    	childNodeMap.put("id", id); 
    	childNodeMap.put("name", name); 
    	childNodeMap.put("sort", sort); 
    	childNodeMap.put("parent_id", parent_id);
    	childNodeMap.put("parent_name",parent_name);
    	return groupService.updateDepartNode(childNodeMap);
    }
    
    @RequestMapping(value = "/deleteDepartNode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deleteDepartNode(HttpServletRequest request) {
    	String ids = request.getParameter("ids");
    	List<String> list = Arrays.asList(ids.split(","));
    	return groupService.deleteDepartNode(list);
    }
    @RequestMapping(value = "/listPagePriv", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String listPagePriv(HttpServletRequest request) {
    	Map<String,Object> map = getPagerMap(request);
    	return groupService.listPagePriv(map);
    }
    @RequestMapping(value = "/addPriv", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String addPriv(HttpServletRequest request) {
    	Map<String, Object> map  = requestParameterToMap(request);
    	String id=UUID.randomUUID().toString();//id
    	map.put("id", id);
    	return groupService.addPriv(map);
    }
    @RequestMapping(value = "/deletePriv", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deletePriv(HttpServletRequest request) {
    	Map<String,String> m = new HashMap<String,String>();
    	m.put("ids", request.getParameter("ids"));
    	return groupService.deletePriv(m);
    }
    @RequestMapping(value = "/updatePriv", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updatePriv(HttpServletRequest request) {
    	Map<String, Object> map  = requestParameterToMap(request);
    	return groupService.updatePriv(map);
    }
    @RequestMapping(value = "/getPrivMenuTree", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getPrivMenuTree(HttpServletRequest request) {
    	String priv_id = request.getParameter("priv_id");
    	return groupService.getPrivMenuTree(priv_id);
    }
    @RequestMapping(value = "/initDataPriv", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String initDataPriv(HttpServletRequest request) {
    	return groupService.initDataPriv(requestParameterToMap(request));
    }
    @RequestMapping(value = "/getDataPriv", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getDataPriv(HttpServletRequest request) {
    	return groupService.getDataPriv(requestParameterToMap(request));
    }
    @RequestMapping(value = "/updateDataPriv", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateDataPriv(HttpServletRequest request) {
    	return groupService.updateDataPriv(requestParameterToMap(request));
    }
    @RequestMapping(value = "/updatePrivMenu", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updatePrivSysMenu(HttpServletRequest request) {
    	String priv_id = request.getParameter("priv_id");
    	String ids = request.getParameter("treeId");
    	Map<String,Object> map = new HashMap<String,Object>();
    	map.put("id", priv_id);
    	map.put("menu", ids);
    	return groupService.updatePrivMenu(map);
    }
    @RequestMapping(value = "/listPageUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String listPageUser(HttpServletRequest request) {
    	Map<String,Object> map = getPagerMap(request);
    	map.putAll(requestParameterToMap(request));
    	return groupService.listPageUser(map);
    }
    @RequestMapping(value = "/listPageCompany", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String listPageCompany(HttpServletRequest request) {
    	Map<String,Object> map = getPagerMap(request);
    	map.putAll(requestParameterToMap(request));
    	return groupService.listPageCompany(map);
    }
    @RequestMapping(value = "/listPriv", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String listPriv(HttpServletRequest request) {
    	return groupService.listPriv();
    }
    @RequestMapping(value = "/addUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String addUser(HttpServletRequest request) {
    	Map<String,Object> map = requestParameterToMap(request);
    	map.put("user_id", UUID.randomUUID().toString());
    	return groupService.addUser(map);
    }
    @RequestMapping(value = "/addCompany", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String addCompany(HttpServletRequest request) {
    	Map<String,Object> map = requestParameterToMap(request);
    	return groupService.addCompany(map);
    }
    @RequestMapping(value = "/deleteCompany", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deleteCompany(HttpServletRequest request) {
    	Map<String,Object> map = requestParameterToMap(request);
    	return groupService.deleteCompany(map);
    }
    @RequestMapping(value = "/updateUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateUser(HttpServletRequest request) {
    	Map<String,Object> map = requestParameterToMap(request);
    	return groupService.updateUser(map);
    }
    @RequestMapping(value = "/updateCompany", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateCompany(HttpServletRequest request) {
    	Map<String,Object> map = requestParameterToMap(request);
    	return groupService.updateCompany(map);
    }
    @RequestMapping(value = "/getUserById", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getUserById(HttpServletRequest request) {
    	Map<String,Object> map = requestParameterToMap(request);
    	return groupService.getUserById(map);
    }
    @RequestMapping(value = "/deleteUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deleteUser(HttpServletRequest request) {
    	Map<String,String> m = new HashMap<String,String>();
    	m.put("ids", request.getParameter("ids"));
    	return groupService.deleteUser(m);
    }
    /**
     * 伪删除
     * @param request
     * @return
     */
    @RequestMapping(value = "/deleteUser1", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deleteUser1(HttpServletRequest request) {
    	Map<String,String> m = new HashMap<String,String>();
    	m.put("ids", request.getParameter("ids"));
    	return groupService.deleteUser1(m);
    }
    
    @RequestMapping(value = "/getUnit", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getUnit(HttpServletRequest request) {
    	return groupService.getUnit();
    }
    @RequestMapping(value = "/listPageUnit", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String listPageUnit(HttpServletRequest request) {
    	Map<String,Object> map = getPagerMap(request);
    	return groupService.listPageUnit(map);
    }
    @RequestMapping(value = "/addUnit", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String addUnit(HttpServletRequest request) {
    	return groupService.addUnit(requestParameterToMap(request));
    }
    @RequestMapping(value = "/updateUnit", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateUnit(HttpServletRequest request) {
    	return groupService.updateUnit(requestParameterToMap(request));
    }
    @RequestMapping(value = "/deleteUnit", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deleteUnit(HttpServletRequest request) {
    	return groupService.deleteUnit(requestParameterToMap(request));
    }
    @RequestMapping(value = "/getSystemTypeTree", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getSystemTypeTree(HttpServletRequest request) {
    	return groupService.getSystemTypeTree("0",request.getParameter("type"));
    }
    @RequestMapping(value = "/getSystemTypeBox", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getSystemTypeBox(HttpServletRequest request) {
    	return groupService.getSystemTypeBox("0",request.getParameter("type"));
    }
    @RequestMapping(value = "/getSystemType", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getSystemType(HttpServletRequest request) {
    	return groupService.getSystemType();
    }
    @RequestMapping(value = "/getSystemTypeById", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getSystemTypeById(HttpServletRequest request) {
    	return groupService.getSystemTypeById(requestParameterToMap(request));
    }
    @RequestMapping(value = "/addSystemType", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String addSystemType(HttpServletRequest request) {
    	return groupService.addSystemType(requestParameterToMap(request));
    }
    @RequestMapping(value = "/updateSystemType", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateSystemType(HttpServletRequest request) {
    	return groupService.updateSystemType(requestParameterToMap(request));
    }
    @RequestMapping(value = "/listPageWareHouse", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String listPageWareHouse(HttpServletRequest request) {
    	Map<String,Object> map = getPagerMap(request);
    	return groupService.listPagePriv(map);
    }
    @RequestMapping(value = "/getCompanyByNameOrId", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getCompanyByNameOrId(HttpServletRequest request) {
    	return groupService.getCompanyByNameOrId(requestParameterToMap(request));
    }
    @RequestMapping(value = "/deleteSystemType", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deleteSystemType(HttpServletRequest request) {
    	return groupService.deleteSystemType(requestParameterToMap(request));
    }
    @RequestMapping(value = "/addFBItem", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String addFBItem(HttpServletRequest request) {
    	return groupService.addFBItem(requestParameterToMap(request));
    }
    @RequestMapping(value = "/updateFBItem", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateFBItem(HttpServletRequest request) {
    	return groupService.updateFBItem(requestParameterToMap(request));
    }
    @RequestMapping(value = "/deleteFBItem", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String deleteFBItem(HttpServletRequest request) {
    	return groupService.deleteFBItem(requestParameterToMap(request));
    }
    @RequestMapping(value = "/listPageFBItem", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String listPageFBItem(HttpServletRequest request) {
    	Map<String,Object> map = getPagerMap(request);
    	return groupService.listPageFBItem(map);
    }
    @RequestMapping(value = "/getFBItem", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getFBItem(HttpServletRequest request) {
    	return groupService.getFBItem();
    }
    @RequestMapping(value = "/updateGdPerson", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String updateGdPerson(HttpServletRequest request) {
    	Map<String,String> m = new HashMap<String,String>();
    	m.put("ids", request.getParameter("ids"));
    	m.put("gdAdmin", request.getParameter("gdAdmin"));
    	m.put("gdAdminId", request.getParameter("gdAdminId"));
    	return groupService.updateGdPerson(m);
    }
    @RequestMapping(value = "/getBusinessView", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody String getBusinessView(HttpServletRequest request) {
    	Map<String,String> m = new HashMap<String,String>();
    	m.put("flow_run_id", request.getParameter("flow_run_id"));
    	return groupService.getBusinessView(m);
    }
}
